import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../constants/sp_key.dart';

class LanguageViewModel extends GetxController {
  Rx<Locale> locale = Rx(const Locale.fromSubtags(languageCode: "zh"));

  LanguageViewModel() {
    SharedPreferences.getInstance().then((value) {
      changeLocale(value.getInt(keyLanguage));
    });
  }

  changeLocale(int? languageId) {
    locale.value = languageId == 1
        ? const Locale.fromSubtags(languageCode: "zh")
        : const Locale.fromSubtags(languageCode: "en");
  }
}
